package data

import (
	"fmt"
	goSpider "github.com/Flyits/goSpider/src"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
)

var Db *gorm.DB

func Init(spider *goSpider.Spider) {
	var err error
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", spider.Config.Data["username"], spider.Config.Data["password"], spider.Config.Data["host"], spider.Config.Data["port"], spider.Config.Data["database"])
	Db, err = gorm.Open("mysql", dsn)
	if err != nil {
		panic(err)
	}
}
